//
//  ItemToAdd.swift
//  Fancyswap
//
//  Created by Jonathan Muschalle on 2015-03-22.
//  Copyright (c) 2015 Jonathan Muschalle. All rights reserved.
//

import UIKit

class ItemToAdd {
    
    var name:String = "no-name"
    var brand:String = "no-brand"
    var paidPrice:String = "0"
    var description:String = "no-description"
    var images:[String] = []
    var formId:String = "no-formId"
    var size:String = "no-size"
    var condition:String = "1"
    var coins:String = "0"
    var promocode:String = ""
    
    init(name: String, brand: String, price: String,
        description: String, images: [String], formId: String,
        size: String, condition: String, coins: String, promocode: String){
            self.name = name
            self.brand = brand
            self.paidPrice = price
            self.description = description
            self.images = images
            self.formId = formId
            self.size = size
            self.condition = condition
            self.coins = coins
            self.promocode = promocode
    }
    
    func toJsonParameter() -> [String: AnyObject] {
        return [
            "name":name,
            "brand":brand,
            "paidPrice":paidPrice,
            "description":description,
            "images": images,
            "formId":formId,
            "size":size,
            "condition":condition,
            "coins":coins,
            "promocode":promocode
        ];
    }
    
    class func createDummyItemFromPictureListToAdd(pictures: PictureListToAdd) -> ItemToAdd {
        var images:[String] = []
        var pics = pictures.getPicturesUploaded()
        for pic in pics {
            images.append("\(pic.getUniqueName()).png")
        }
        let date = NSDate()
        let uniqueNameTimeStamp = date.timeIntervalSince1970
        return ItemToAdd(
            name: "Dummy Name",
            brand: "Dummy Brand",
            price: "79",
            description: "Dummy-Lorem-\(uniqueNameTimeStamp)",
            images: images,
            formId: "\(pictures.getUploadFormId())",
            size: "M",
            condition: "1",
            coins: "1456",
            promocode: "")
    }
    
    class func createItem(
        name : NSString,
        brand : NSString,
        price : NSString,
        description : NSString,
        size : NSString,
        condition : NSString,
        coins : NSString,
        pictures: PictureListToAdd) -> ItemToAdd {
        var images:[String] = []
        var pics = pictures.getPicturesUploaded()
        for pic in pics {
            images.append("\(pic.getUniqueName()).png")
        }
        let date = NSDate()
        let uniqueNameTimeStamp = date.timeIntervalSince1970
        return ItemToAdd(
            name: name,
            brand: brand,
            price: price,
            description: description,
            images: images,
            formId: "\(pictures.getUploadFormId())",
            size: size,
            condition: condition,
            coins: coins,
            promocode: "")
    }
   
}
